package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SceneBook;
import com.ruoyi.system.service.ISceneBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 景区门票预订Controller
 * 
 * @author xdh
 * @date 2024-06-26
 */
@RestController
@RequestMapping("/booking/scenebook")
public class SceneBookController extends BaseController
{
    @Autowired
    private ISceneBookService sceneBookService;

    /**
     * 查询景区门票预订列表
     */
    @PreAuthorize("@ss.hasPermi('booking:scenebook:list')")
    @GetMapping("/list")
    public TableDataInfo list(SceneBook sceneBook)
    {
        startPage();
        List<SceneBook> list = sceneBookService.selectSceneBookList(sceneBook);
        return getDataTable(list);
    }

    /**
     * 导出景区门票预订列表
     */
    @PreAuthorize("@ss.hasPermi('booking:scenebook:export')")
    @Log(title = "景区门票预订", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SceneBook sceneBook)
    {
        List<SceneBook> list = sceneBookService.selectSceneBookList(sceneBook);
        ExcelUtil<SceneBook> util = new ExcelUtil<SceneBook>(SceneBook.class);
        util.exportExcel(response, list, "景区门票预订数据");
    }

    /**
     * 获取景区门票预订详细信息
     */
    @PreAuthorize("@ss.hasPermi('booking:scenebook:query')")
    @GetMapping(value = "/{scenicBookingId}")
    public AjaxResult getInfo(@PathVariable("scenicBookingId") Integer scenicBookingId)
    {
        return success(sceneBookService.selectSceneBookByScenicBookingId(scenicBookingId));
    }

    /**
     * 新增景区门票预订
     */
    @PreAuthorize("@ss.hasPermi('booking:scenebook:add')")
    @Log(title = "景区门票预订", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SceneBook sceneBook)
    {
        return toAjax(sceneBookService.insertSceneBook(sceneBook));
    }

    /**
     * 修改景区门票预订
     */
    @PreAuthorize("@ss.hasPermi('booking:scenebook:edit')")
    @Log(title = "景区门票预订", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SceneBook sceneBook)
    {
        return toAjax(sceneBookService.updateSceneBook(sceneBook));
    }

    /**
     * 删除景区门票预订
     */
    @PreAuthorize("@ss.hasPermi('booking:scenebook:remove')")
    @Log(title = "景区门票预订", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scenicBookingIds}")
    public AjaxResult remove(@PathVariable Integer[] scenicBookingIds)
    {
        return toAjax(sceneBookService.deleteSceneBookByScenicBookingIds(scenicBookingIds));
    }
}
